<template>
  <div class="box">
    <div class="left">积云教育学生管理</div>
    <div class="right">
      <div class="right_con">
        <p>欢迎登录</p>
        <el-form
          ref="ruleFormRef"
          :model="ruleForm"
          :rules="rules"
          class="demo-ruleForm"
          status-icon
        >
          <el-form-item prop="username">
            <el-input v-model="ruleForm.username" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="ruleForm.password" type="password" show-password />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm(ruleFormRef)"
              >登录</el-button
            >
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, reactive, toRefs } from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
import { ElMessage } from 'element-plus'
export default {
  name: "",
  setup() {
    const router = useRouter();
    const route = useRoute();
    const store = useStore();
    const data = reactive({
      ruleForm: {
        username: "admin",
        password: "123456",
      },
      rules: {
        username: [
          {
            message: "用户名不能为空",
            trigger: "blur",
          },
          {
            min: 3,
            max: 5,
            message: "用户名在3到5个字符",
          },
        ],
        password: [
          {
            message: "密码不能为空",
            trigger: "blur",
          },
          {
            min: 3,
            max: 11,
            message: "密码在3到11个字符",
          },
        ],
      },
    });
    // 登录
    const submitForm = () => {
      store.dispatch("getlogin", data.ruleForm).then((res) => {
        if (res.code == 200) {
          ElMessage({
            message: res.msg,
            type: "success",
          });
          router.push('/qianduan')
        }
      });
    };

    // 重置账号密码
    const resetForm = () => {
      data.ruleForm = {
        username: "admin",
        password: "123456",
      };
    };
    return {
      ...toRefs(data),
      resetForm,
      submitForm,
    };
  },
};
</script>

<style scoped lang='scss'>
.box {
  width: 100%;
  height: 100%;
  display: flex;
  .left {
    flex: 2;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #19284e;
    color: #f99600;
    font-weight: 700;
    font-size: 30px;
  }
  .right {
    flex: 1;
    height: 100%;
    background: #2b3589;
    display: flex;
    align-items: center;
    justify-content: center;
    .right_con {
      p {
        color: #6d9ed5;
        margin-bottom: 20px;
        font-size: 26px;
        text-align: center;
      }
    }
  }
}
</style>